/**
 * 
 */
package com.wubo.sec.model;

import java.io.Serializable;
import java.util.Date;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

import com.wubo.sec.acl.GroupAcl;
import com.wubo.sec.acl.core.AclModel;
import com.wubo.sec.acl.core.GlobalAcl;
import com.wubo.sec.config.LangUtil;

/** 用户组
 * @author WuBo
 * @CreateDate 2010-7-30
 * @version 1.0.01
 */
@Entity
@Table(name="SEC_GROUP")
@Cache(usage=CacheConcurrencyStrategy.READ_WRITE)
public class Group implements Serializable, Cloneable, AclModel {
	private static final long serialVersionUID = 8486973047591234460L;

	public static final int SUPER = 80; //特级
	
	public static final int HIGH = 60; //高级
	
	public static final int MID = 40; //中级
	
	public static final int LOW = 20; //低级
	
	public static final String DEFAULT_MARK = "SYSTEM";
	
	public static final Group DEFAULT_GROUP = new Group("DEFAULT_GROUP", LangUtil.get("DefaultGroup"));
	
	public Group(){
		
	}
	
	public Group(String code, String name){
		this.code = code;
		this.name = name;
	}
	
	public GlobalAcl getAcl() {
		return new GroupAcl(this);
	}
	
	@Id
	@Column(unique=true, nullable=true, length=32)
	private String code; //编码，主键
	@Column(nullable=true, length=50)
	private String name; //组名
	
	private int priority = MID; //优先级
	
	@Column(nullable=true, length=50)
	private String mark = DEFAULT_MARK; //标识码
	
	private boolean markLocked; //标识码锁定，锁定标识码的组只对同标识码且优先级低的组优先
	
	private String desn; //描述
	
	private Date createTime; //创建时间
	private String createUser; //创建用户
	private Date updateTime; //修改时间
	private String updateUser; //修改用户
	
	@OneToMany(fetch=FetchType.LAZY, mappedBy="group")
	private Set<User> users;

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getPriority() {
		return priority;
	}

	public void setPriority(int priority) {
		this.priority = priority;
	}

	public String getMark() {
		return mark;
	}

	public void setMark(String mark) {
		this.mark = mark;
	}

	public String getDesn() {
		return desn;
	}

	public void setDesn(String desn) {
		this.desn = desn;
	}

	public Set<User> getUsers() {
		return users;
	}

	public void setUsers(Set<User> users) {
		this.users = users;
	}

	public boolean isMarkLocked() {
		return markLocked;
	}

	public void setMarkLocked(boolean markLocked) {
		this.markLocked = markLocked;
	}
	
	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	public String getCreateUser() {
		return createUser;
	}

	public void setCreateUser(String createUser) {
		this.createUser = createUser;
	}

	public Date getUpdateTime() {
		return updateTime;
	}

	public void setUpdateTime(Date updateTime) {
		this.updateTime = updateTime;
	}

	public String getUpdateUser() {
		return updateUser;
	}

	public void setUpdateUser(String updateUser) {
		this.updateUser = updateUser;
	}

	public Group clone(){
		try{
			return (Group) super.clone();
		}catch(CloneNotSupportedException e){
			return null;
		}
	}
	
}
